package com.ryzx.example.service;

import com.querydsl.jpa.impl.JPAQueryFactory;
import com.ryzx.example.repository.ComputerBookRepository;
import com.ryzx.example.vo.ComputerBook;
import com.ryzx.example.vo.QPublisher;
import com.ryzx.jpa.helper.base.BapBaseRepository;
import com.ryzx.jpa.helper.base.BapBaseServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
import com.ryzx.example.vo.QComputerBook;

@Service
public class ComputerBookService extends BapBaseServiceImpl<ComputerBook,Long> {
    public ComputerBookService(JPAQueryFactory jpaQueryFactory, BapBaseRepository<ComputerBook, Long> bapBaseRepository) {
        super(jpaQueryFactory, bapBaseRepository);
    }
    @Resource
    ComputerBookRepository computerBookRepository;
    public ComputerBook findByPublisher(String publisher){
        return computerBookRepository.findByPublisher(publisher);
    }
    public List<ComputerBook> findV(){
        QComputerBook computerBook=QComputerBook.computerBook;
        return jpaQueryFactory.select(computerBook).from(computerBook).fetch();
    }
    public List<ComputerBook> findX(){
        QComputerBook computerBook=QComputerBook.computerBook;
        QPublisher publisher=QPublisher.publisher;
        return jpaQueryFactory.select(computerBook)
                .from(computerBook)
                .leftJoin(publisher)
                .on(computerBook.publisher.eq(publisher.name))
                .where(publisher.year.gt(10))
                .fetch();
    }
}
